package cn.zwx.security.example.service.impl;

import cn.zwx.security.example.entity.SysUserEntity;
import cn.zwx.security.example.entity.extend.SelfUserEntity;
import cn.zwx.security.example.mapper.SysUserMapper;
import cn.zwx.security.example.service.SelfUserDetailsService;
import cn.zwx.security.example.service.SysUserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @description:
 * @projectName:spring-boot-security-example
 * @see:cn.zwx.security.example.service.impl
 * @author:zhangwenxue
 * @createTime:2021/6/23 16:47
 * @version:1.0
 */
@Service
public class SelfUserDetailsServiceImpl implements SelfUserDetailsService {

    @Autowired
    private SysUserService sysUserService;

    /**
     * @description 查询用户信息
     * @return cn.zwx.security.example.entity.extend.SelfUserEntity
     * @author zhangwenxue
     * @createTime 2021/6/23 18:39
     **/
    @Override
    public SelfUserEntity loadUserByUsername(String userName) {
        // 查询用户信息
        SysUserEntity sysUserEntity =sysUserService.loadUserByUsername(userName);
        if (sysUserEntity!=null){
            // 组装参数
            SelfUserEntity selfUserEntity = new SelfUserEntity();
            BeanUtils.copyProperties(sysUserEntity,selfUserEntity);
            return selfUserEntity;
        }
        return null;
    }
}
